from django.shortcuts import redirect, reverse


# 登录装饰器，浏览页面判断用户是否已经登录，登录就显示，没有登录就跳转登录界面
def login_required(func):
    def wrapper(request, *args, **kwargs):
        if request.front_user:
            return func(request, *args, **kwargs)
        else:
            return redirect(reverse('users:login'))

    return wrapper
